package org.chengn.level_easy.context383;

/**
 * @Title: Context383
 * @Author ChengN
 * @Package org.chengn.level_easy.context383
 * @Date 2024/1/7 0:11
 * @description: 赎金信
 */
public class Context383 {
    public boolean canConstruct(String ransomNote, String magazine) {
        if (ransomNote.length() > magazine.length()) return false;
        int[] ans = new int[26];
        for (int i = 0; i < magazine.length(); ++i) {
            ans[(int)magazine.charAt(i) - 'a']++;
        }
        for (int i = 0; i < ransomNote.length(); ++i) {
            int idx = (int)ransomNote.charAt(i) - 'a';
            if (ans[idx] == 0) return false;
            ans[idx]--;

        }
        return true;
    }
}
